package com.roin.learn.activiti.controller;

import com.roin.learn.activiti.service.ProcessFormService;
import org.activiti.engine.form.FormProperty;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import java.util.List;

/**
 * 流程表单业务Controller
 */
@Controller
@RequestMapping("process/form")
public class ProcessFormController {
    @Resource
    ProcessFormService processFormService;

    /**
     * 获取流程定义的启动表单Html
     * @param processDefintionId 流程定义ID
     * @return 表单Html字符串
     */
    @RequestMapping("getStartFromHtml.do")
    @ResponseBody
    public String getStartFromHtml(String processDefintionId){
        String html = processFormService.getStartFromHtml(processDefintionId);
        return html;
    }
    /**
     * 查看流程任务的表单
     * @param processDefintionId 流程定义ID
     * @return
     */
    @RequestMapping("viewStartFromHtml.htm")
    public String viewStartFromHtml(String processDefintionId, Model model){
        List<FormProperty> properties = processFormService.getStartFormProperties(processDefintionId);
        model.addAttribute("properties",properties);
        return "template/processForm";
    }

    /**
     * 获取流程任务的表单Html
     * @param taskId 任务ID
     * @return 表单Html字符串
     */
    @RequestMapping("getTaskFormHtml.do")
    @ResponseBody
    public String getTaskFormHtml(String taskId){
        String html = processFormService.getTaskFormHtml(taskId);
        return html;
    }
    /**
     * 查看流程任务的表单
     * @param taskId 任务ID
     * @return
     */
    @RequestMapping("viewTaskFormHtml.htm")
    public String viewTaskFormHtml(String taskId, Model model){
        List<FormProperty> properties = processFormService.getTaskFormProperties(taskId);
        model.addAttribute("properties",properties);
        return "template/processForm";
    }
}
